﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 人事工资管理系统
{
    public partial class frmAddUserRedeploy : Form
    {
        public frmAddUserRedeploy()
        {
            InitializeComponent();
        }
        PMSClass.DBOperate operate = new PMSClass.DBOperate();
        SqlConnection conn = PMSClass.DBConnection.MyConnection();
        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" ||
               dateTimePicker1.Text.Trim() == "" || textBox4.Text.Trim() == "" ||
               textBox5.Text.Trim() == "" || textBox6.Text.Trim() == "" ||
               textBox7.Text.Trim() == "" || textBox8.Text.Trim() == "" || textBox9.Text.Trim() == "" || textBox10.Text.Trim() == "")
            {
                MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                string strSql = "insert into tb_redeploy(UID,UName,URemoveDate,UOldDep,UNewDep,UOldJob,UNewJob,UOldPay,UNewpay,UPayExplain)values('" + comboBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + dateTimePicker1.Text + "','" + textBox4.Text + "','" + textBox5.Text.Trim() + "','" + textBox6.Text + "','" + textBox7.Text.Trim() + "','" + textBox8.Text.Trim() + "','" + textBox9.Text + "','" + textBox10.Text.Trim() + "')";
                        int num = operate.OperateData(strSql);
                        if (num > 0)
                        {
                            MessageBox.Show("员工调动成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        string strsql1 = "update set tb_employee where employeeDept='"+textBox5+"'";
                        string strsql2 = "update set tb_employee where employeeDuty='" + textBox7 + "'";
                        string strsql3 = "update set tb_employee where employeePay='" + textBox9 + "'";
                        operate.OperateData(strsql1);
                        operate.OperateData(strsql2);
                        operate.OperateData(strsql3);
                    }
                }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmAddUserRedeploy_Load(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tb_employee", conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                comboBox1.Items.Add(sdr["employeeID"].ToString());
            }
            sdr.Close();
            conn.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = "select * from tb_employee where employeeID='" + comboBox1.Text + "'";
            DataSet ds = operate.GetTable(str);
            ds.Dispose();
            textBox2.Text = ds.Tables[0].Rows[0][2].ToString();
            textBox4.Text = ds.Tables[0].Rows[0][4].ToString();
            textBox6.Text = ds.Tables[0].Rows[0][8].ToString();
            textBox8.Text = ds.Tables[0].Rows[0][12].ToString();
        }

       
            }
        }

        
    

